{extends 'base/site2.html'}
{block name="page_header"}{include file="common/header.html" inline}{/block}
{block name="page_nav"}{include file="common/slide-nav.html" inline}{/block}
{block name="page_styles"}
    <link rel="stylesheet" type="text/css" href="/css/mediation/entryrepay/index.css" />

{/block}

{block name="page_section"}


    <div class="sessionPage bg-fff">

        <input type="hidden" id="delete_id" value="">
        <div class="page-header">
            <span class="line"></span>
            <strong class="tit"><font color="#1474FA"  >{$smarty.get.litigantName}</font>   -还款计划详情</strong>
            <button type="button" data-target="#modal_add" data-toggle="modal" class="btn btn-info textright btn-xs" style="float: right;margin-right: 20px;">新增</button>

        </div>
        <div style="width: 95%; margin: 0 auto;overflow: auto;">

          <table class="table table-striped table-bordered table-hover text-nowrap">
            <thead>
            <tr>
                <th scope="col">期数</th>
                <th scope="col">还款状态</th>
                <th scope="col">预计还款金额</th>
                <th scope="col">实际还款金额</th>
                <th scope="col">预计还款日期</th>
                <th scope="col">实际还款日期</th>
                <th scope="col">添加时间</th>
                <th scope="col">更新时间</th>
                <th scope="col">还款备注</th>
                <th scope="col" class="fix-ele">操作</th>
            </tr>
            </thead>

            <tbody>
            {if $list}
                {foreach from=$list item=info key=key name=a}
                    <tr>
                        <td>{$info['idTmp']}</td>

                        <td>{$planStatusArr[$info['status']]}{if $info['status'] == 'reject_plan'}(原因：<font color="red">{$info['notesCheck']}</font>){/if}</td>
                        <td>{$info['repayAmount']}</td>
                        <td>{$info['realRepayAmount']}</td>
                        <td>{if !empty($info['repaymentDate'])}{$info['repaymentDate']|date_format:"%Y/%m/%d"}{/if}</td>
                        <td>{if !empty($info['realRepaymentDate'])}{$info['realRepaymentDate']|date_format:"%Y/%m/%d"}{else}-{/if}</td>
                        <td>{if !empty($info['addTime'])}{$info['addTime']|date_format:"%Y/%m/%d"}{/if}</td>
                        <td>{if !empty($info['updateTime'])}{$info['updateTime']|date_format:"%Y/%m/%d"}{else}-{/if}</td>
                        <td>{$info['notes']}</td>

                        <td class="fix-ele">
                            {if $info['status'] != 'finish_plan' }
                            <a href="javascript:;"  class="editTransfer"  data-toggle="modal" data-target="#modal_edit" data-id='{$info['id']}' data-repayAmount='{$info['repayAmount']}' data-notes='{$info['notes']}' data-repaymentDate='{$info['repaymentDate']|date_format:"%Y-%m-%d"}'>修改计划</a>
                            {/if}
                            {if $info['status'] == 'keep_plan' }
                                <a href="javascript:;"  class='transfer'  data-toggle="modal" data-target="#modal_upload" data-id="{$info['id']}" data-filepath='{$info['filepath']}' data-realRepayAmount='{$info['realRepayAmount']}' data-realRepaymentDate='{$info['realRepaymentDate']|date_format:"%Y-%m-%d"}'>录入还款</a>
                            {/if }
                            {if $info['status'] == 'reject_plan'}
                                <a href="javascript:;"  class='transfer'  data-toggle="modal" data-target="#modal_upload" data-id="{$info['id']}" data-filepath='{$info['filepath']}' data-realRepayAmount='{$info['realRepayAmount']}' data-realRepaymentDate='{$info['realRepaymentDate']|date_format:"%Y-%m-%d"}'>重新录入还款</a>
                            {/if }
                            {if $info.filepath }
                            <a href="../{$info.filepath}" target="_blank" class='withdraw_one' >查阅凭证</a>
                            {/if }
                           {if $info['status'] == 'reject_plan' || $info['status'] == 'no_repay' }
                            <a  onclick="confirm('请确认是否删除该条数据？') ? clickDel(this,{$info.id}) : '' " >删除</a>
                            {/if}
                        </td>
                    </tr>
                {/foreach}
            {/if}
            </tbody>
        </table>
        </div>

    </div>
    <div class="modal fade" id="modal_upload" tabindex="-1" role="dialog" aria-labelledby="confirmLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form style="display:block">
                    <input type="hidden" name="detail_id" id="detail_id" value="0">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="confirmLabel">上传凭证</h4>
                    </div>
                    <div class="modal-body" style="padding-left: 100px;display:flex;flex-direction:column;">
                        <div class="form-group col-lg-10 ui-select">
                            <label for="exampleInputName2"  class="col-sm-3 control-label">实际还款日期:</label>
                            <div class="col-sm-9">
                                <input type="date" class="form-control"  id="realRepaymentDate"  value="" name="realRepaymentDate" placeholder="实际还款日期">
                            </div>
                        </div>
                        <div class="form-group col-lg-10 ui-select">
                            <label for="inputEmail3" class="col-sm-3 control-label">实际还款金额:</label>
                            <div class="col-sm-9">
                                <input type="number" name="realRepayAmount"  class="form-control" id="realRepayAmount" step="0.01" value="" placeholder="实际还款金额,保留2位小数" data-valid="notempty" >
                            </div>

                        </div>
                        <div class="form-group col-lg-10 ui-select" style="margin-top:15px">
                            <label for="inputEmail3" class="col-sm-3 control-label"></font>还款备注:</label>
                            <div class="col-sm-9">
                                <textarea name="notes" class="form-control" rows="5"  id="notes"></textarea>
                            </div>
                        </div>
                       <div class="form-group" >
                           <label for="inputEmail3" class="col-sm-3 control-label">还款凭证:</label>

                           <div class="row mr-none">
                                <input type="file" id="inputFile"  style="width:60%;padding-left:14px;">
                            </div>
                            <span class="error-tips"></span>
                        </div>

                        <div class="form-group" >
                            <input type="hidden" name="filePath" value="" id="historyFilePath">
                            <img src=""  style="width: 70px;" id="img_filepath">
                        </div>
                    </div>
                    <div class="modal-footer" >
                        <button type="button" id="confirmSubmit" class="btn btn-primary modal_upload_sure">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>



    <div class="modal fade" id="modal_edit" tabindex="-1" role="dialog" aria-labelledby="refusal_modal" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <form id="modal_edit_form">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">修改</h4>
                    </div>
                    <div class="modal-body" style="padding-left: 100px;height: 150px">
                        <input type="hidden" name="detail_id" id="detail_id2" value="0">
                        <div class="form-group col-lg-10 ui-select" style="display:flex;">
                            <label for="exampleInputName2"  class="col-sm-4 control-label">还款日期:</label>
                            <div class="col-sm-9">
                                <input type="date" class="form-control"  id="repaymentDate"  value="" name="repaymentDate" placeholder="还款日期">
                            </div>
                        </div>
                        <div class="form-group col-lg-10 ui-select" style="margin-top:15px;display:flex;">
                            <label for="inputEmail3" class="col-sm-4 control-label">偿还金额:</label>
                            <div class="col-sm-9">
                                <input type="number" name="repayAmount" class="form-control" id="repayAmount" step="0.01" value="" placeholder="请输入~" data-valid="notempty">
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer" style="text-align: center;">
                        <button type="button" class="btn btn-default" id="fpclosebtn" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary modal_edit_sure">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="refusal_modal" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <form id="modal_add_form">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">新增</h4>
                    </div>
                    <div class="modal-body" style="padding-left: 100px;height: 180px">
                        <input type="hidden" name="plan_id" id="plan_id" value="{$smarty.get.id}">
                        <div class="form-group col-lg-10 ui-select" style="display:flex;">
                            <label for="exampleInputName2"  class="col-sm-4 control-label">还款日期:</label>
                            <div class="col-sm-9">
                                <input type="date" class="form-control"  id="repaymentDate"  value="" name="repaymentDate" placeholder="还款日期">
                            </div>
                        </div>
                        <div class="form-group col-lg-10 ui-select" style="margin-top:15px;display:flex;">
                            <label for="inputEmail3" class="col-sm-4 control-label">偿还金额:</label>
                            <div class="col-sm-9">
                                <input type="number" name="repayAmount" class="form-control" id="repayAmount" step="0.01" value="" placeholder="请输入~" data-valid="notempty">
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer" style="text-align: center;">
                        <button type="button" class="btn btn-default" id="fpclosebtn" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary modal_add_sure">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>



{/block}
{block name="page_scripts"}
<script type="text/javascript">

    $(".transfer").on("click",function(){

        $("#detail_id").val($(this).attr("data-id"));
        $("#realRepaymentDate").val($(this).attr("data-realRepaymentDate"));
        $("#realRepayAmount").val($(this).attr("data-realRepayAmount"));

        $("#img_filepath").attr("src","../"+$(this).attr("data-filepath"));
        $("#historyFilePath").val($(this).attr("data-filepath"));
    });

    var lockfas= false;
    $(".modal_upload_sure").on("click",function(){
        if(lockfas)return;
        lockfas = true;

        if($("#detail_id").val()==0){
            toastr.error('参数错误');
            return false;
        }

        var data = new FormData();
        data.append('detail_id', $("#detail_id").val());
        data.append('realRepaymentDate', $("#realRepaymentDate").val());
        data.append('realRepayAmount', $("#realRepayAmount").val());
        data.append('filePath', $("#historyFilePath").val());
        $.each($('#inputFile')[0].files, function(i, file) {
            data.append('file', file);
        })
        $.ajax({
            type: "post",
            url:"/returnedmoneyplan/detailEditUpload",
            contentType: false, //不可缺
            processData: false,    //不可缺
            data: data,
            dataType:'json',
            success:function(res){
                if(res.code==200){
                    lockfas = false;
                    toastr.success(res.message);
                    setTimeout(function(){
                        window.location.reload();
                    },2000)
                }else{
                    lockfas = false;
                    toastr.error(res.message);
                }
            }
        })
        lockfas = false;

    })




    $(".editTransfer").on("click",function(){

        $("#detail_id2").val($(this).attr("data-id"));
        $("#repaymentDate").val($(this).attr("data-repaymentDate"));
        $("#repayAmount").val($(this).attr("data-repayAmount"));
        $("#notes").text($(this).attr("data-notes"));

        // $("#modal_upload").show();
    });


    $(".modal_edit_sure").on("click",function(){
        if(lockfas)return;
        lockfas = true;

        if($("#detail_id2").val()==0){
            toastr.error('参数错误');
            return false;
        }

        $.ajax({
            type: "post",
            url:"/returnedmoneyplan/detailEdit",
            data:$("#modal_edit_form").serialize(),
            dataType:'json',
            success:function(res){
                if(res.code==200){
                    lockfas = false;
                    toastr.success(res.message);
                    setTimeout(function(){
                        window.location.reload();
                    },2000)
                }else{
                    lockfas = false;
                    toastr.error(res.message);
                }
            }
        })
        lockfas = false;

    })


    $(".modal_add_sure").on("click",function(){
        if(lockfas)return;
        lockfas = true;

        if($("#plan_id").val()==0){
            toastr.error('参数错误');
            return false;
        }

        $.ajax({
            type: "post",
            url:"/returnedmoneyplan/detailadd",
            data:$("#modal_add_form").serialize(),
            dataType:'json',
            success:function(res){
                if(res.code==200){
                    lockfas = false;
                    toastr.success(res.message);
                    setTimeout(function(){
                        window.location.reload();
                    },2000)
                }else{
                    lockfas = false;
                    toastr.error(res.message);
                }
            }
        })
        lockfas = false;

    })


    function clickDel($this,id){
       var _this= $(this) ;
        if($(this).attr('disabled')){
            return false;
        }
        $(this).attr('disabled',true);
        $.ajax({
            url:"/returnedmoneyplan/deldetail",
            method:"post",
            data:{
                detail_id:id
            },
            success:function(res){
                if(res.code==200){
                    toastr.success(res.message);
                    document.location.reload();
                }else{
                    toastr.error(res.message);
                }
                _this.attr('disabled',false);
            }
        })

    }





</script>
{/block}
